package ru.jexp.mvc.snippet;

import java.util.Date;

import ru.jexp.mvc.Event;
import ru.jexp.mvc.IListener;
import ru.jexp.mvc.SubscriberListener;

public class SnippetController extends SubscriberListener {

	private SnippetBean bean;

	public SnippetController(SnippetBean bean) {
		super();
		this.bean = bean;
	}

	public void init() {
		initHandlers();

		notifyAll(new Event(SnippetEvents.EVENT1, bean.getInteger(), this));
		notifyAll(new Event(SnippetEvents.EVENT2, bean.getDate(), this));
	}

	private void initHandlers() {
		mapEvent(SnippetEvents.EVENT1, new IListener() {
			public void handle(Event e) {
				System.out.println(SnippetController.this + "::Handle("
						+ e.type + ") bean.setInteger(" + e.data + ")");
				bean.setInteger((Integer) e.data);
			}
		});
		mapEvent(SnippetEvents.EVENT2, new IListener() {
			public void handle(Event e) {
				System.out.println(SnippetController.this + "::Handle("
						+ e.type + ") bean.setDate(" + e.data + ")");
				bean.setDate((Date) e.data);
			}
		});

	}
}
